﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
using WinFormsApp1.Common;
using SlaughterItem.Common.Domains.RBAC;
using System.Text.Json;
using WinFormsApp1.SuYi.week1WinForm;

namespace WinFormsApp1
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private async void button1_Click(object sender, EventArgs e)
        {
            var userName = this.textBox1.Text;
            var userPwd = this.textBox2.Text;
            UserLogin userLogin = new(userName, userPwd);


            var res = await HttpClientHelper.RequestUrl<UserLogin, ApiResult<string>>("http://localhost:5106/api/Week01Get/", "UsersLosing", HttpClientHelper.MethodType.POST, userLogin);

            if (res.Code == 1)
            {
                MessageBox.Show("登录成功");
                Main3 main = new Main3();
                main.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("登录失败");
                return;
            }



            //string url = @"http://localhost:5106/api/Week01Get/UsersAdd";
            //HttpClient client = new HttpClient();


            //var content = new StringContent(JsonSerializer.Serialize<UserLogin>(userLogin),Encoding.UTF8);
            //content.Headers.Remove("Content-Type");
            //content.Headers.Add("Content-Type", "application/json");

            //string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;


            //if (result!=null)
            //{
            //    MessageBox.Show("登录成功");
            //    Main main = new Main();
            //    main.Show();
            //    this.Hide();
            //}
            //else
            //{
            //    MessageBox.Show("登录失败");
            //}

        }
        /// <summary>
        /// 跳转页面 到 注册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            UsersAdd usersAdd = new UsersAdd();
            usersAdd.Show();
            this.Hide();
        }

        public record UserLogin(string UsersName, string UsersPwd);
    }
}
